<template>
	<div class="setting-user">
		<div class="setting-card">
			<div class="setting-item-title">密码设置</div>
			<div class="setting-item-content">
				<el-input placeholder="请输入访问密码" v-model="form.password" clearable>
				</el-input>
			</div>
		</div>
		<div class="setting-card">
			<div class="setting-item-title">权限设置</div>
			<div class="setting-item-content">
				<div class="item">
					<span>非密码访问</span> <el-switch v-model="form.noPwd"></el-switch>
				</div>
			</div>
		</div>
		<div class="setting-card">
			<div class="setting-item-title">简历编写</div>
			<div class="setting-item-content">
		    	<markdown-editor v-model="form.content" :configs="markdownOption" :highlight="true"></markdown-editor>
			</div>
		</div>
		<sub-foot :prompt="prompt" :loading="loading" @saveChange="save"></sub-foot>
	</div>
</template>

<script>
	import {markdownEditor} from 'vue-simplemde'
	import SubFoot from 'components/setting/sub-foot'
    import {mapMutations} from 'vuex'

	export default {
		data() {
			return {
				prompt: '这些将控制你的简历页面权限以及内容',
				form: {
					noPwd: false,
					password: '',
					content: ''
				},
				markdownOption: {
                    status: true,
                    renderingConfig: {
                        codeSyntaxHighlighting: true,
                        highlightingTheme: 'atom-one-light'
                    }
                },
				loading: false
			}
		},
		created() {
			this.__getResume()
		},
		methods: {
			save() {
				this.loading = true
				this.$http.post('setResumeInfo',this.form).then((response) => {
					this.setResume({allow:this.form.noPwd})
					this.loading = false
					this.$notify({
			          title: '简历设置操作成功',
			          message: '缓存将在10分钟后重新生成',
			          type: 'success'
			        })
				})
			},
			__getResume() {
				this.$http.get('resumeInfo').then((response) => {
					this.form.noPwd = response.data.nopwd == 1
					this.form.content = response.data.content
				})
			},
			...mapMutations({
            	setResume: 'SET_RESUME',
	        })
		},
		components: {
			markdownEditor,SubFoot
		}
	}
</script>

<style scope>
@import '../../../static/css/simplemk.css'
</style>